//
//  OrderdetailViewController.m
//  Housekeeping
//
//  Created by 刘建峰 on 16/5/30.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "OrderdetailViewController.h"
#import "PayTypeViewController.h"
#import "EvaluationViewController.h"
@interface OrderdetailViewController ()
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UILabel *indentNumber;//订单编号
@property (weak, nonatomic) IBOutlet UILabel *greatDate;//下单时间
@property (weak, nonatomic) IBOutlet UILabel *indentStatus;//订单状态
@property (weak, nonatomic) IBOutlet UILabel *indentMoney;//需付金额
@property (weak, nonatomic) IBOutlet UILabel *dateTime;//预约时间
@property (weak, nonatomic) IBOutlet UILabel *payType;//支付方式
@property (weak, nonatomic) IBOutlet UILabel *connectPerson;//联系人
@property (weak, nonatomic) IBOutlet UILabel *connectPhone;//手机号
@property (weak, nonatomic) IBOutlet UILabel *serviceAdderss;//服务地址
@property (strong, nonatomic) IBOutlet UILabel *note;//备注
@property (weak, nonatomic) IBOutlet UILabel *servicerNmae;//阿姨姓名
@property (weak, nonatomic) IBOutlet UILabel *servicerPhone;//阿姨电话
@property (weak, nonatomic) IBOutlet UIButton *payButton;
@property (weak, nonatomic) IBOutlet UIView *maskView;

@property (strong, nonatomic) NSMutableDictionary *labelDic;

@end

@implementation OrderdetailViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hadPay) name:@"hadPay" object:@"1"];
    _labelDic = [NSMutableDictionary dictionary];
    [self initViewLayout];
    _labelDic = [NSMutableDictionary dictionary];
    
    [self NetworkRequest];
    
}


- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 500), NO);
    _scroView.showsVerticalScrollIndicator = NO;
}


#pragma mark === 支付
- (IBAction)payHandel:(UIButton *)sender {
    if ([sender.titleLabel.text isEqualToString:@"支 付"]) {
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"IndentsStoryboard" bundle:nil];
        PayTypeViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"PayType"];
        page.payOrderPrice = [NSString stringWithFormat:@"%@",self.labelDic[@"goodsAllPrice"]];
        page.payOrderName = [NSString stringWithFormat:@"%@",self.labelDic[@"goodsInfo"][0][@"goodsName"]];
        page.payId = self.labelDic[@"mordNo"];
        [[Common getNavigation]pushViewController:page];

    }else if ([sender.titleLabel.text isEqualToString:@"评 论"]){
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"IndentsStoryboard" bundle:nil];
        EvaluationViewController *evaluationVC = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Evaluation"];
        
        evaluationVC.mgcoOrderDetailId = [NSString stringWithFormat:@"%@",_mordId];
        evaluationVC.CommodityInformationDic = _commentInfoDic;
        
        [[Common getNavigation]pushViewController:evaluationVC];
    }
    
}


- (void)hadPay{
    [self backBtn];
}



- (void)GetOrderDetails {
    self.indentNumber.text = [NSString stringWithFormat:@"订单编号：%@",self.labelDic[@"mordNo"]];
    self.greatDate.text = [NSString stringWithFormat:@"下单时间：%@",self.labelDic[@"mordCreateTime"]];
    NSInteger a = [self.labelDic[@"mordStatus"]integerValue];
    switch (a) {
        case 1:{
            self.indentStatus.text = @"未支付";
            [_payButton setTitle:@"支 付" forState:UIControlStateNormal];
            _maskView.hidden = NO;
            break;
        }
        case 2:{
            self.indentStatus.text = @"未支付";
             [_payButton setTitle:@"支 付" forState:UIControlStateNormal];
            _maskView.hidden = YES;
            break;
        }
        case 3:{
            self.indentStatus.text = @"待评价";
             [_payButton setTitle:@"评 论" forState:UIControlStateNormal];
             _payButton.backgroundColor = [UIColor colorWithRed:0.996 green:0.467 blue:0.004 alpha:1.000];
             _maskView.hidden = YES;
            break;
        }
        case 4:{
            self.indentStatus.text = @"交易完成";
             [_payButton setTitle:@"交易成功" forState:UIControlStateNormal];
             _maskView.hidden = YES;
            break;
        }
        
    }
    self.indentMoney.text =  [NSString stringWithFormat:@"￥%@",self.labelDic[@"goodsAllPrice"]];

    self.dateTime.text =[NSString stringWithFormat:@"预约时间：%@",self.labelDic[@"mordAppointTime"]];
    if (a==3||a==4) {
        NSInteger b = [self.labelDic[@"mordPaymentId"]integerValue];
        switch (b) {
            case 1:{
                self.payType.text = @"支付方式： 支付宝";
                break;
            }
            case 2:{
                self.payType.text = @"支付方式：微信";
                break;
            }
            case 3:{
                self.payType.text = @"支付方式：电子钱包";
                break;
            }
        }
  
    }else{
           self.payType.text = @"支付方式：暂未支付";
    }
       self.connectPerson.text = [NSString stringWithFormat:@"联系人：%@",self.labelDic[@"museTrueName"]];
    self.connectPhone.text = [NSString stringWithFormat:@"手机号：%@",self.labelDic[@"musePhone"]];
    
    self.serviceAdderss.text = [NSString stringWithFormat:@"%@",self.labelDic[@"museAddress"]];
    //行间距
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:self.serviceAdderss.text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
    [style setLineSpacing:15.0f];
    CGFloat textWidth = 1;
    NSInteger leng = textWidth;
    if (attStr.length < textWidth) {
        leng = attStr.length;
    }
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, leng)];
    self.serviceAdderss.attributedText = attStr;
    [self.serviceAdderss sizeToFit];

    
    self.note.text = [NSString stringWithFormat:@"备注：%@",self.labelDic[@"mordRemark"]];
    
    self.servicerNmae.text = [NSString stringWithFormat:@"阿姨姓名：%@",self.labelDic[@"msexName"]];
    self.servicerPhone.text = [NSString stringWithFormat:@"阿姨电话：%@",self.labelDic[@"msexPhone"]];

    
}

#pragma mark - 返回
- (IBAction)back:(id)sender {
    [self backBtn];
}
#pragma mark - 网络请求
- (void)NetworkRequest {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    [dic setObject:self.mordId forKey:@"mordId"];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:HK_queryAppMallOrderDetail withHttpType:@"POST" withTag:HK_HK_queryAppMallOrderDetail];
    
}

#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==HK_HK_queryAppMallOrderDetail) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            self.labelDic = database[@"result"];
            
            [self GetOrderDetails];
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"hadPay" object:@"1"];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
